package rulebase;

import java.util.ArrayList;
import java.util.List;

import commondata.IPlayer;
import commondata.ITradeRule;
import commondata.TradeOptionStruct;

public class RemainingYear implements ITradeRule{
	
	private static final int BASE_YEAR = 1;

	public void isTradeApplicable(TradeOptionStruct tradeOptionStruct) {
		List<String> result = new ArrayList<String>();
		
		checkPlayerContratYears(tradeOptionStruct.getFirstTeamPlayers(),result);
		
		
		checkPlayerContratYears(tradeOptionStruct.getSecondTeamPlayers(),result);
		
		if(result.size()> 0) {
			String message = "Exclude player(s) with single year contract to make this trade successful.";
			result.add(message);
		}
		tradeOptionStruct.getRuleEngineResults().addAll(result);
	}

	private void checkPlayerContratYears(List<IPlayer> playerList,
			List<String> result) {
		String message = "";
		for (IPlayer player : playerList) {
			if(player.getRemainingYear() == BASE_YEAR){
				message = player.getPlayerName() + " " +player.getPlayerSurname()+" has a single year contract and he has no-trade clause."; 
				result.add(message);
			}
		}
	
	}

}
